﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using EpsiRisk.MoteurJeu;

namespace EpsiRisk.AffichageJeu
{
    public class ClassZoneAffectationRenforts : ClassZoneContextuelle
    {
        private Texture2D spriteSoldat;
        private Texture2D spriteCanon;
        private Texture2D spriteCavalier;
        private Texture2D spriteAll;

        private ClassBouton boutonSoldat;
        private ClassBouton boutonCanon;
        private ClassBouton boutonCavalier;
        private ClassBouton boutonAll;

        private int renforts1
        {
            get { return ClassEtatPartie.renforts - renforts10 * 10 - renforts5 * 5; }
        }
        private int renforts5
        {
            get { return (ClassEtatPartie.renforts - 1 - renforts10 * 10) / 5; }
        }
        private int renforts10
        {
            get { return (ClassEtatPartie.renforts - 6) / 10; }
        }


        internal override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            spriteBatch.Begin();
            spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, renforts1.ToString(), new Vector2(position.X + 5, position.Y + 60), Color.Black, 0, new Vector2(), 1, SpriteEffects.None, 0);
            spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, renforts5.ToString(), new Vector2(position.X + 75, position.Y + 60), Color.Black, 0, new Vector2(), 1, SpriteEffects.None, 0);
            spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, renforts10.ToString(), new Vector2(position.X + 145, position.Y + 60), Color.Black, 0, new Vector2(), 1, SpriteEffects.None, 0);
            spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, "Pays selectionne :", new Vector2(position.X + 300, position.Y + 6), Color.Red);
            if (ClassEtatPartie.sousTerritoireSelectionne != null)
            {
                //enleve les accents du nom 
                string tmp = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.GetEncoding(1251).GetBytes(ClassEtatPartie.sousTerritoireSelectionne.Nom));
                spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, tmp, new Vector2(position.X + 300, position.Y + 26), Color.Red);
            }
            else
            {
                spriteBatch.DrawString(ClassDonneesGlobales.SpriteTxt, "Aucun", new Vector2(position.X + 300, position.Y + 26), Color.Red);
            }
            spriteBatch.End();
        }

        internal override void initialiser(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            spriteSoldat = content.Load<Texture2D>("Sprites/Soldats/soldat");
            spriteCavalier = content.Load<Texture2D>("Sprites/Soldats/cavalier");
            spriteCanon = content.Load<Texture2D>("Sprites/Soldats/canon");
            spriteAll = content.Load<Texture2D>("Sprites/Soldats/all");
            boutonSoldat = new ClassBouton(spriteSoldat);
            boutonSoldat.position = new Vector2(3, 10);
            boutonSoldat.height = 73;
            boutonSoldat.width = 59;
            AddBouton(boutonSoldat);
            boutonSoldat.Clicked += new EventHandler(boutonSoldat_Clicked);
            boutonCavalier = new ClassBouton(spriteCavalier);
            boutonCavalier.position = new Vector2(73, 10);
            boutonCavalier.height = 73;
            boutonCavalier.width = 59;
            AddBouton(boutonCavalier);
            boutonCavalier.Clicked += new EventHandler(boutonCavalier_Clicked);
            boutonCanon = new ClassBouton(spriteCanon);
            boutonCanon.position = new Vector2(143, 10);
            boutonCanon.height = 73;
            boutonCanon.width = 59;
            AddBouton(boutonCanon);
            boutonCanon.Clicked += new EventHandler(boutonCanon_Clicked);
            boutonAll = new ClassBouton(spriteAll);
            boutonAll.position = new Vector2(213, 10);
            boutonAll.height = 73;
            boutonAll.width = 59;
            AddBouton(boutonAll);
            boutonAll.Clicked += new EventHandler(boutonAll_Clicked);
        }

        void boutonCanon_Clicked(object sender, EventArgs e)
        {
            ClassEtatPartie.affecterRenfort(10);
            Console.WriteLine("Clic sur affecter 10 renfort");
            if (ClassEtatPartie.renforts == 0)
                ClassEtatPartie.terminerPhase();
        }

        void boutonCavalier_Clicked(object sender, EventArgs e)
        {
            ClassEtatPartie.affecterRenfort(5);
            Console.WriteLine("Clic sur affecter 5 renfort");
            if (ClassEtatPartie.renforts == 0)
                ClassEtatPartie.terminerPhase();
        }

        void boutonSoldat_Clicked(object sender, EventArgs e)
        {
            ClassEtatPartie.affecterRenfort(1);
            Console.WriteLine("Clic sur affecter 1 renfort");
            if(ClassEtatPartie.renforts == 0)
                ClassEtatPartie.terminerPhase();
        }

        void boutonAll_Clicked(object sender, EventArgs e)
        {
            ClassEtatPartie.affecterRenfort(ClassEtatPartie.renforts);
            Console.WriteLine("Clic sur affecter tous les renforts");
            ClassEtatPartie.terminerPhase();
        }
    }
}
